package com.shxc.smarttrade.account.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.shxc.smarttrade.R;
import com.shxc.smarttrade.login.activity.LoginHomeActivity;
import com.shxc.smarttrade.old.activity.QuickOrderProtocolActivity;
import com.shxc.smarttrade.old.activity.TradeAccountActivity;
import com.shxc.smarttrade.base.BaseActivity;
import com.shxc.smarttrade.dialog.SubmitDialog;
import com.shxc.smarttrade.old.utils.SpUtils;
import com.shxc.smarttrade.utils.AppUtils;
import com.shxc.smarttrade.old.utils.CloseAllActivity;
import com.shxc.smarttrade.utils.ToastUtils;
import com.umeng.analytics.MobclickAgent;

import org.xchris.view.annotation.ContentView;
import org.xchris.view.annotation.Event;
import org.xchris.view.annotation.ViewInject;

/**
 * 设置
 */
@ContentView(R.layout.activity_setting_c)
public class SettingActivity extends BaseActivity {
    @ViewInject(R.id.title_textview)
    TextView title_textview;
    @ViewInject(R.id.left_imageview)
    ImageView left_imageview;
    @ViewInject(R.id.deal_account_textview)
    TextView deal_account_textview;//交易账户
    @ViewInject(R.id.place_textview)
    TextView place_textview;//快速下单
    @ViewInject(R.id.close_textview)
    TextView close_textview;//快速平仓

   private SubmitDialog submitDialog;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        title_textview.setText("设置");
        left_imageview.setVisibility(View.VISIBLE);

        submitDialog = new SubmitDialog(this,getResources().getIdentifier("MyDialog", "style", getPackageName()));
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
        deal_account_textview.setText(spImp.getAccType() == 0 ? "模拟账户" : "老虎账户");
        place_textview.setText(spImp.isFastOpen() ? "开" : "关");
        close_textview.setText(spImp.isFastClose() ? "开" : "关");
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);

    }

    @Event({R.id.left_imageview, R.id.account_setting_view, R.id.deal_account_view, R.id.place_view, R.id.close_view, R.id.help_view, R.id.weixin_view, R.id.aboutus_view, R.id.exit_button})
    private void onClickk(View view) {

        switch (view.getId()) {
            case R.id.left_imageview:
                //关闭
                finish();
                break;
            case R.id.account_setting_view:
                //个人信息编辑
                JumpTo(AccountSettingActivity.class);
                break;
            case R.id.deal_account_view:
                //交易账户
                JumpTo(TradeAccountActivity.class);//旧
                break;
            case R.id.place_view:
                //快速下单
                Intent intentOrder = new Intent(this, QuickOrderProtocolActivity.class);
                intentOrder.putExtra("tag", 0);
                startActivity(intentOrder);//旧
                break;
            case R.id.close_view:
                //快速平仓
                Intent intentClose = new Intent(this, QuickOrderProtocolActivity.class);
                intentClose.putExtra("tag", 1);
                startActivity(intentClose);//旧
                break;
            case R.id.help_view:
                //帮助中心
                JumpTo(HelpCenterActivity.class);
                break;
            case R.id.weixin_view:
                //客服微信
                AppUtils.copyText(this, "whjyds168");
                ToastUtils.showToast("复制成功");
                break;
            case R.id.aboutus_view:
                //关于我们
                JumpTo(AccountAboutUsActivity.class);
                break;
            case R.id.exit_button:
                //退出
                submitDialog.showDialog("是否退出账号？");
                submitDialog.getCancel_textview().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        submitDialog.dismiss();
                    }
                });
                submitDialog.getSubmit_textview().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
//                        CloseAllActivity.getScreenManager().clearAllActivity();

                        String email = spImp.getEmail();

                        spImp.clear();
                        spImp.setFirstOpen(false);
                        spImp.setEmail(email);

                        SharedPreferences setPreferences = getSharedPreferences(
                                "app", Context.MODE_PRIVATE);
                        SharedPreferences.Editor editor = setPreferences.edit();
                        editor.clear();
                        editor.commit();

                        SpUtils.putBoolean(SettingActivity.this, "firstOpen", false);
                        startActivity(new Intent(SettingActivity.this, LoginHomeActivity.class));
                        finish();

//                        MobclickAgent.onEvent(SettingActivity.this, "login");//友盟统计该点击事件发生次数
                        submitDialog.dismiss();
                    }
                });
                break;
        }
    }
}
